home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / imagen.trm < prev    next >
Text File  |  1993-09-15  |  17KB  |  741 lines

  1. /*
  2.  * $Id: imagen.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  */
  4.  
  5. /* GNUPLOT - imagen.trm */
  6. /*
  7.  * Copyright (C) 1990   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   Imagen laser printers
  25.  *
  26.  * AUTHORS
  27.  *   Paul E. McKenney, David Kotz
  28.  *   Rewritten/extended by:
  29.  *    Hans Olav Eggestad
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  * 
  32.  */
  33.  
  34. /*
  35.  * Original for direct Imagen output (but retaining many of the
  36.  * LaTeX extensions) by Paul E. McKenney, 1989.
  37.  * Further modified by David Kotz to fit into gnuplot 2.0.
  38.  * Information Science and Technology Division, SRI International,
  39.  * 333 Ravenswood Ave, Menlo Park, CA 94025.
  40.  * Mail to mckenney@sri.com.
  41.  */
  42.  
  43. #include "impcodes.h"
  44.  
  45. #define IMAGEN_PTS_PER_INCH (300)
  46. #define IMAGEN_A4_H  (IMAGEN_PTS_PER_INCH * 83 / 10) /* default is landscape */
  47. #define IMAGEN_A4_W  (IMAGEN_PTS_PER_INCH * 116 / 10)
  48.  
  49. #define IMAGEN_XMAX (IMAGEN_PTS_PER_INCH * 11) /* 10.0 inches */
  50. #define IMAGEN_YMAX (IMAGEN_PTS_PER_INCH * 78 / 10) /* 7.5 inches */
  51.  
  52. static int IMAGEN_Xmax = IMAGEN_XMAX;  /* width in current orientation */
  53. static int IMAGEN_Ymax = IMAGEN_YMAX;
  54.  
  55. #define IMAGEN_FONTSIZE 12
  56. #define IMAGEN_FONT "cour"
  57.  
  58. #define IMAGEN_HTIC (20)
  59. #define IMAGEN_VTIC (20)
  60. #define IMAGEN_VCHAR (IMAGEN_FONTSIZE*5)
  61. #define IMAGEN_HCHAR (IMAGEN_VCHAR/2)
  62.  
  63. unsigned short IMP_gmap[128];
  64. unsigned char IMP_chmap[256];
  65.  
  66. static int IMAGEN_page_h  = IMAGEN_A4_H;
  67. static int IMAGEN_page_w = IMAGEN_A4_W;
  68. static int IM_win_horiz = 1;
  69. static int IM_win_verti = 1;
  70. static int IM_plot_nr = 0;
  71.  
  72. static int IMAGEN_fontsize = IMAGEN_FONTSIZE;
  73. static int IMAGEN_familytable[36];
  74. static int IMAGEN_orgX;        /* absolute-pixel-ORIgin of graph page.    */
  75. static int IMAGEN_orgY;
  76. static int IMAGEN_orgx;        /* absolute-pixel-ORIgin of current graph. */
  77. static int IMAGEN_orgy;
  78. static int IMAGEN_posx;        /* current drawing position (lines).    */
  79. static int IMAGEN_posy;
  80. static int IMAGEN_inplot;
  81. static int IMAGEN_xmax = IMAGEN_XMAX;    /* width of graph in pixels.    */
  82. static int IMAGEN_ymax = IMAGEN_YMAX;    /* height of graph in pixels.    */
  83. static int IMAGEN_winx = IMAGEN_XMAX;    /* width of window in pixels.    */
  84. static int IMAGEN_winy = IMAGEN_YMAX;    /* height of window in pixels.    */
  85. static int IMAGEN_hchar;    /* Height of CHAR in current font.    */
  86. static int IMAGEN_wchar;    /* Width of CHAR in current font.    */
  87. static int IMAGEN_blofs;    /* BaseLine OFfSet from bounding box.    */
  88. static int IMAGEN_angle = -1;    /* 0 for horizontal text, 1 for vertical */
  89. static int IMAGEN_portrait;    /* 0 for landscape */
  90. static enum JUSTIFY IMAGEN_justify = LEFT; /* left/center/right */
  91.  
  92. static IMAGEN_seq_pos;        /* position in sequence */
  93.  
  94. static void IMAGEN_putwd();
  95. static void IMAGEN_createfamily();
  96. static void IMAGEN_setfont();
  97. static void IMAGEN_setpos();
  98. void IMP_set_draw_pattern();
  99. static unsigned char *IMAGEN_cvts();
  100.  
  101. /* char IMPdrpattern[10][10] = { {0}, {30,10,0}, {0}, {10,30,0}, {2,20,0}, 
  102.     {20,10,0}, {30,20,10,20,0}, {30,20,4,10,10,10,4,20,0}, {40,20,0}, {30,15,4,15,0}
  103. };
  104. */
  105.  
  106. char IMPdrpattern[10][10] = { 
  107. /* -2 */ {0}, 
  108. /* -1 */ {1,8,0}, 
  109. /*  0 */ {0}, 
  110. /*  1 */ {16,4,0}, 
  111. /*  2 */ {3,8,0}, 
  112. /*  3 */ {8,8,0}, 
  113. /*  4 */ {16,6,3,6,0}, 
  114. /*  5 */ {16,6,8,6,0}, 
  115. /*  6 */ {16,4,1,4,8,4,1,4,0}, 
  116. /*  7 */ {16,4,1,8,1,4,0}
  117. };
  118.  
  119. IMAGEN_init()
  120. {
  121.     register struct termentry *t = &term_tbl[term];
  122.  
  123.     /* char font[10];    */        /* font name */
  124.  
  125.     IMAGEN_posx = IMAGEN_posy = 0;
  126.  
  127.     IMAGEN_orgX = (IMAGEN_page_w - IMAGEN_Xmax) / 2;
  128.     IMAGEN_orgY = (IMAGEN_page_h - IMAGEN_Ymax) / 2;
  129.  
  130.     IMAGEN_xmax = IMAGEN_winx = (int)(IMAGEN_Xmax / IM_win_horiz);
  131.     IMAGEN_ymax = IMAGEN_winy = (int)(IMAGEN_Ymax / IM_win_verti);
  132.  
  133.     t->xmax = (unsigned int)(IMAGEN_xmax);
  134.     t->ymax = (unsigned int)(IMAGEN_ymax);
  135.  
  136.     fputs("@document(language impress, paper a4)", outfile);
  137.  
  138.     if (IMAGEN_portrait) {
  139.         putc(imP_SET_ABS_V, outfile);
  140.         IMAGEN_putwd(3520);
  141.     }
  142.     putc(imP_SET_HV_SYSTEM, outfile);
  143.     putc(((IMAGEN_portrait?3:0)<<5)|(3<<3)|(IMAGEN_portrait?0:5), outfile);
  144.  
  145.     /* sprintf(font, "cour%02d", IMAGEN_FONTSIZE); */
  146.     IMAGEN_mapsinit();
  147.     IMAGEN_createmap(1,IMP_gmap);
  148.     /* IMAGEN_createfamily(font, IMAGEN_FONTSIZE); */
  149.     IMAGEN_setfont(IMAGEN_fontsize);
  150.  
  151.     IMAGEN_text_angle(0);
  152.  
  153.     putc(imP_SET_ABS_H, outfile);
  154.     IMAGEN_putwd(0);
  155.     putc(imP_SET_ABS_V, outfile);
  156.     IMAGEN_putwd(0);
  157.  
  158.     IMAGEN_linetype(-1);
  159. }
  160.  
  161. IM_page()
  162. {
  163.     putc(imP_ENDPAGE, outfile);
  164.     putc(imP_PAGE, outfile);
  165. }
  166.  
  167. IMAGEN_graphics()
  168. {
  169.     int tmpx, tmpy;
  170.  
  171.     if ( IM_plot_nr >= ( IM_win_horiz * IM_win_verti )) {
  172.     IM_page();
  173.     IM_plot_nr = 0;
  174.     }
  175.     IM_plot_nr++;
  176.     tmpx = IMAGEN_orgX + ((IM_plot_nr - 1) % IM_win_horiz) * IMAGEN_winx;
  177.     tmpy = IMAGEN_orgY + ((IM_win_verti - 1) - (int)((IM_plot_nr - 1) / IM_win_horiz)) * IMAGEN_winy;
  178.     IMAGEN_orgx = tmpx + (int)((IMAGEN_winx - IMAGEN_xmax)/2);
  179.     IMAGEN_orgy = tmpy + (int)((IMAGEN_winy - IMAGEN_ymax)/2);
  180. }
  181.  
  182. IMAGEN_options()
  183. {
  184.     extern struct value *const_express();
  185.     extern double real();
  186.     struct value a;
  187.  
  188.     while (!END_OF_COMMAND) {
  189.         if (almost_equals(c_token,"p$ortrait")) {
  190.             IMAGEN_portrait=TRUE;
  191.             IMAGEN_page_h = IMAGEN_A4_W;
  192.             IMAGEN_page_w = IMAGEN_A4_H;
  193.             IMAGEN_Xmax = IMAGEN_YMAX;
  194.             IMAGEN_Ymax = IMAGEN_XMAX;
  195.             c_token++;
  196.         }
  197.         else if (almost_equals(c_token,"l$andscape")) {
  198.             IMAGEN_portrait=FALSE;
  199.             c_token++;
  200.         } else if (equals(c_token,"[")) { /* windows spesified */
  201.             c_token++;
  202.             if (IM_plot_nr>1)
  203.             if (equals(c_token,"]")) {
  204.                 IM_page();
  205.                 c_token++;
  206.                 continue;
  207.             }
  208.             if (END_OF_COMMAND) {
  209.                     int_error("no. windows: [horizontal,vertical] expected",c_token);
  210.             } else if (!equals(c_token,","))  {
  211.                 IM_win_horiz = (int)real(const_express(&a));
  212.             }    
  213.             if (!equals(c_token,","))
  214.                 int_error("',' expected",c_token);
  215.             c_token++;
  216.             if (!equals(c_token,"]")) {
  217.                 IM_win_verti = (int)real(const_express(&a));
  218.              }
  219.             if (!equals(c_token,"]"))
  220.                   int_error("expecting ']'",c_token);
  221.             c_token++;
  222.         } else {
  223.             /* We have font size specified */
  224.             IMAGEN_fontsize = (int)real(const_express(&a));
  225.             if ( IMAGEN_fontsize < 8 ) 
  226.                 IMAGEN_fontsize = 8;
  227.             if ( IMAGEN_fontsize > 15 ) 
  228.                 IMAGEN_fontsize = 15;
  229.         }
  230.     }
  231.     sprintf(term_options,"%d %s [%1d,%1d]",IMAGEN_fontsize,(IMAGEN_portrait)?"portrait":"landscape",IM_win_horiz,IM_win_verti);
  232. }
  233.  
  234.  
  235. IMAGEN_text()
  236. {
  237. }
  238.  
  239. IMAGEN_scale(xs, ys)
  240.     double xs, ys;            /* scaling factors */
  241. {
  242.     register struct termentry *t = &term_tbl[term];
  243.  
  244.     /* we change the table for use in graphics.c and IMAGEN_graphics */
  245.     t->xmax = (unsigned int)(xs * IMAGEN_winx);
  246.     IMAGEN_xmax = t->xmax ;
  247.     t->ymax = (unsigned int)(ys * IMAGEN_winy);
  248.     IMAGEN_ymax = t->ymax ;
  249.  
  250.     return TRUE ;
  251. }
  252.  
  253. #define DRAW_PATTERNS 6
  254.  
  255.  
  256. IMAGEN_linetype(lt)
  257. int lt;
  258. {
  259.     static int lastlinetype = -10;
  260.     int pen;
  261.  
  262. /* -2: axis
  263.    -1: border
  264.     0: arrow
  265.     1-7: graph
  266. */
  267.     if (lt == -2) {
  268.         pen = 4;
  269.     } else {
  270.         pen = (int) (lt/8)*2;
  271.         if ( pen <= 0 ) pen = 1;
  272.     }
  273.     lt  = (lt % 8) +2;
  274.  
  275.     if (lastlinetype == lt)
  276.      return;
  277.  
  278.     lastlinetype = lt;    
  279.  
  280.     putc(imP_SET_PEN, outfile);
  281.     putc(pen, outfile);
  282.     IMP_set_draw_pattern(lt,pen);
  283. }
  284.  
  285.  
  286. IMAGEN_move(x,y)
  287.     unsigned int x,y;
  288. {
  289.     IMAGEN_posx = x;
  290.     IMAGEN_posy = y;
  291. }
  292.  
  293. IMAGEN_vector(ux,uy)
  294.     unsigned int ux,uy;
  295. {
  296.     /* Create path. */
  297.  
  298.     putc(imP_CREATE_PATH, outfile);
  299.     IMAGEN_putwd(2);
  300.     IMAGEN_putwd(IMAGEN_posx + IMAGEN_orgx);
  301.     IMAGEN_putwd(IMAGEN_posy + IMAGEN_orgy);
  302.     IMAGEN_putwd(ux + IMAGEN_orgx);
  303.     IMAGEN_putwd(uy + IMAGEN_orgy);
  304.  
  305.     /* Draw path with black pen. */
  306.  
  307.     putc(imP_DRAW_PATH, outfile);
  308.     putc(15, outfile);
  309.  
  310.     /* Set current position to end of line. */
  311.  
  312.     IMAGEN_move(ux, uy);
  313. }
  314.  
  315. static void
  316. IMAGEN_setpos(ux, uy)
  317.     int ux,uy;
  318. {
  319.     /* Set x and y position (for text), also set beginning-of-line. */
  320.  
  321.     putc(imP_SET_ABS_H, outfile);
  322.     IMAGEN_putwd(ux + IMAGEN_orgx);
  323.     putc(imP_SET_ABS_V, outfile);
  324.     IMAGEN_putwd(uy + IMAGEN_orgy);
  325.     putc(imP_SET_BOL, outfile);
  326.     if (IMAGEN_angle == 1)
  327.      IMAGEN_putwd(uy + IMAGEN_orgx); /* vertical */
  328.     else
  329.      IMAGEN_putwd(ux + IMAGEN_orgx); /* horizontal */
  330. }
  331.  
  332. IMAGEN_text_angle(angle)
  333.     int angle;
  334. {
  335.     if (IMAGEN_angle != angle) {
  336.        IMAGEN_angle = angle;    /* record for later use */
  337.        putc(imP_SET_ADV_DIRS, outfile);
  338.        putc(angle == 0 ? 0 : 7, outfile); /* 0=>horiz : 7=>vert */
  339.     }
  340.  
  341.     return(TRUE);
  342. }
  343.  
  344. IMAGEN_justify_text(mode)
  345.     enum JUSTIFY mode;
  346. {
  347.     IMAGEN_justify = mode;
  348.     return(TRUE);
  349. }
  350.  
  351. static unsigned char *
  352. IMAGEN_cvts(str, width, height)
  353.     unsigned char        *str;
  354.     int        *width;
  355.     int        *height;
  356. {
  357.     unsigned char        *cp1;
  358.     unsigned char        *cp2;
  359.     static unsigned char    *buf = NULL;
  360.     int        h;
  361.     int        maxw;
  362.     int        w;
  363.  
  364.     /* Free up old buffer, if there is one, get a new one.  Since    */
  365.     /* all transformations shorten the string, get a buffer that is    */
  366.     /* the same size as the input string.                */
  367.  
  368.     if (buf != NULL)
  369.      (void) free(buf);
  370.     buf = (unsigned char *) alloc(strlen(str) + 1, "converted label string");
  371.  
  372.     /* Do the transformations. */
  373.  
  374.     cp1 = str;
  375.     cp2 = buf;
  376.     h = 1;
  377.     maxw = 0;
  378.     w = 0;
  379.     while (strlen(cp1) > 0) {
  380.        switch (*cp1) {
  381.           case ' ' :        /* Space character. */
  382.             *cp2++ = imP_SP;
  383.             w++;
  384.             break;
  385.             
  386.             case  '\\' :    /* Escape sequence. */
  387.              if (*++cp1 == '\\') {
  388.                 /* Begin new line. */
  389.                 h++;
  390.                 if (w > maxw)
  391.                   maxw = w;
  392.                 w = 0;
  393.                 *cp2++ = '\n';
  394.                 /* *cp2++ = imP_CRLF; */
  395.                 break;
  396.              }
  397.             
  398.             /* Fall through to just copy next char out.    */
  399.             
  400.             default :
  401.              /* *cp2++ = *cp1; */
  402.              *cp2++ = IMP_chmap[*cp1];
  403.             w++;
  404.             break;
  405.         }
  406.        cp1++;
  407.     }
  408.     
  409.     *cp2++ = '\n';
  410.     *cp2 = '\0';
  411.     if (w > maxw)
  412.      maxw = w;
  413.     
  414.     if (height != NULL)
  415.      *height = IMAGEN_angle ?
  416.        IMAGEN_wchar * maxw :
  417.         IMAGEN_hchar * h;
  418.     if (width != NULL)
  419.      *width = IMAGEN_angle ?
  420.        IMAGEN_hchar * h :
  421.         IMAGEN_wchar * maxw;
  422.     return (buf);
  423. }
  424.  
  425. IMAGEN_put_text(x, y, str)
  426.     int x,y;                /* reference point of string */
  427.     unsigned char str[];            /* the text */
  428. {
  429.     unsigned char *cvstr, *p; 
  430.     int height;
  431.     int width;
  432.     int sx, sy;
  433.     
  434.     cvstr = IMAGEN_cvts(str, &width, &height);
  435.  
  436.     if (IMAGEN_angle) {        /* vertical */
  437.     /* x += IMAGEN_hchar; */
  438.        x -= width/2 - IMAGEN_hchar;
  439.       /* y -= height/2; */
  440.     } else                /* horizontal */
  441.      y += height/2 - IMAGEN_hchar;
  442.  
  443. #ifdef sequent
  444.     while ( p=(unsigned char *)index(cvstr,'\n' )) {
  445. #else
  446.     while ( p=(unsigned char *)strchr(cvstr,'\n' )) {
  447. #endif
  448.     *p = '\0';
  449.         sx = x;
  450.         sy = y;
  451.         if ( IMAGEN_angle )
  452.         sx = x - IMAGEN_blofs;
  453.         else
  454.         sy = y + IMAGEN_blofs;
  455.     
  456.         width = strlen(cvstr)*IMAGEN_wchar;
  457.     
  458.         switch (IMAGEN_justify) {
  459.            case LEFT: 
  460.             break;
  461.            case CENTRE: 
  462.             if ( IMAGEN_angle ) {
  463.                 sy = y - width/2;
  464.             } else {
  465.                 sx = x - width/2;
  466.             }
  467.             break;
  468.             /*x -= width/2; break; */
  469.            case RIGHT: 
  470.             if ( IMAGEN_angle ) {
  471.                 sy = y - width;
  472.             } else {
  473.                 sx = x - width;
  474.             }
  475.             break;
  476.             /* x -= width; break; */
  477.         }
  478.  
  479.         IMAGEN_setpos(sx, sy);
  480.         fputs((char*) cvstr, outfile);
  481.     cvstr = ++p;
  482.     if (IMAGEN_angle) {     /* vertical */
  483.         x += IMAGEN_hchar;
  484.     } else {
  485.         y -= IMAGEN_hchar;
  486.     }
  487.  
  488.     }
  489. }
  490.  
  491. IMAGEN_reset()
  492. {
  493.     putc(imP_EOF, outfile);
  494. }
  495.  
  496. static void
  497. IMAGEN_putwd(w)
  498. {
  499.     putc(w>>8, outfile);
  500.     putc(w, outfile);
  501. }
  502.  
  503. static void
  504. IMAGEN_createfamily(c, sz)
  505.     char        *c;
  506.     int        sz;
  507. {
  508.  
  509.     putc(imP_CREATE_FAMILY_TABLE, outfile);
  510.     putc(sz, outfile);
  511.     putc(1, outfile);
  512.     putc(1, outfile);
  513.     /* putc(0, outfile); */
  514.     fputs(c, outfile);
  515.     putc(0, outfile);
  516. }
  517.  
  518. static void
  519. IMAGEN_setfont(sz) 
  520.     int sz;
  521. {
  522.     char font[20];
  523.  
  524.     if ( ! IMAGEN_familytable[sz] ) {
  525.     sprintf(font,"%s%02d",IMAGEN_FONT,sz);
  526.     IMAGEN_createfamily(font, sz);
  527.         IMAGEN_familytable[sz] = sz;
  528.     }
  529.     IMAGEN_hchar = sz * 5;
  530.     IMAGEN_wchar = IMAGEN_hchar / 2;
  531.     IMAGEN_blofs = IMAGEN_hchar / 3;
  532.     term_tbl[term].v_char = IMAGEN_hchar;
  533.     term_tbl[term].h_char = IMAGEN_wchar;
  534.     putc(imP_SET_FAMILY, outfile);
  535.     putc(sz, outfile);
  536.     putc(imP_SET_SP, outfile);
  537.     IMAGEN_putwd(IMAGEN_wchar);
  538.     putc(imP_SET_IL, outfile);
  539.     IMAGEN_putwd(IMAGEN_hchar);
  540. }
  541.  
  542. void
  543. IMP_set_draw_pattern(pattern,sz)
  544. int sz, pattern;
  545. {
  546.     int i;
  547.     putc(imP_SET_DRAW_PATTERN, outfile);
  548.     putc(0,outfile);
  549.     putc(imP_SET_DRAW_PATTERN, outfile);
  550.     /* if ( strlen(IMPdrpattern[pattern]) == 1 ) {
  551.         putc(type,outfile);
  552.         return;
  553.     } */ 
  554.     putc(strlen(IMPdrpattern[pattern]),outfile);
  555.     for ( i=0;i<strlen(IMPdrpattern[pattern]);i++) {
  556.         IMAGEN_putwd(IMPdrpattern[pattern][i]*sz);
  557.     }
  558. }
  559.  
  560.  
  561. IMAGEN_mapsinit()
  562. {
  563.  
  564.     register int i;
  565.  
  566.     for ( i=32;i<127;i++) {
  567.         IMP_gmap[i] = i;
  568.     }
  569.     IMP_gmap[1] = 225;
  570.     IMP_gmap[2]  = 233;
  571.     IMP_gmap[3] = 61736;
  572.     IMP_gmap[4] = 241;
  573.     IMP_gmap[5]  = 249;
  574.     IMP_gmap[6] = 61864;
  575.     IMP_gmap[7] = 162;
  576.     IMP_gmap[8] = 163;
  577.     IMP_gmap[9] = 164;
  578.     IMP_gmap[10] = 165;
  579.     IMP_gmap[11] = 167;
  580.     IMP_gmap[12] = 171;
  581.     IMP_gmap[13] = 182;
  582.     IMP_gmap[14] = 61346;
  583.     IMP_gmap[15] = 191;
  584.     IMP_gmap[16] = 187;
  585.     IMP_gmap[17] = 188;
  586.     IMP_gmap[18] = 189;
  587.     IMP_gmap[19] = 190;
  588.     IMP_gmap[20] = 210;
  589.     IMP_gmap[21] = 211;
  590.     IMP_gmap[22] = 251;
  591.     IMP_gmap[23] = 61232;
  592.     IMP_gmap[24] = 212;
  593.     IMP_gmap[25] = 137;
  594.     IMP_gmap[26] = 176;
  595.     IMP_gmap[27] = 161;
  596.     IMP_gmap[28] = 139;
  597.     IMP_gmap[29] = 133;
  598.     IMP_gmap[30] = 140;
  599.     IMP_gmap[31] = 61249;
  600.     IMP_gmap[32] = 8738;
  601.     IMP_gmap[34] = 186;
  602.     IMP_gmap[36] = 164;
  603.     IMP_gmap[39] = 185;
  604.     IMP_gmap[127] = 61286;
  605.  
  606.     /* for (i=1;i<127;i++) fprintf(stderr,"%d -> %d\n",i,IMP_gmap[i]); */
  607.  
  608.     for ( i=32;i<=127;i++) {
  609.         IMP_chmap [i] = i;
  610.     }
  611.     for ( i=128;i<=255;i++) {
  612.         IMP_chmap [i] = 128; /* first map all non printable chars to SPACE */
  613.     }
  614.  
  615.     IMP_chmap [161] = 27;
  616.     IMP_chmap [162] = 7;
  617.     IMP_chmap [163] = 8;
  618.     IMP_chmap [164] = 120;
  619.     IMP_chmap [165] = 10;
  620.     IMP_chmap [166] = 124;
  621.     IMP_chmap [167] = 11;
  622.     IMP_chmap [168] = 25;
  623.     IMP_chmap [169] = 21;
  624.     IMP_chmap [170] = 45;
  625.     IMP_chmap [171] = 12;
  626.     IMP_chmap [172] = 83;
  627.     IMP_chmap [173] = 45;
  628.     IMP_chmap [174] = 20;
  629.     IMP_chmap [175] = 126;
  630.     IMP_chmap [176] = 26;
  631.     IMP_chmap [177] = 12;
  632.     IMP_chmap [178] = 1;
  633.     IMP_chmap [179] = 2;
  634.     IMP_chmap [180] = 29;
  635.     IMP_chmap [181] = 52;
  636.     IMP_chmap [182] = 13;
  637.     IMP_chmap [183] = 5;
  638.     IMP_chmap [184] = 28;
  639.     IMP_chmap [185] = 3;
  640.     IMP_chmap [186] = 45;
  641.     IMP_chmap [187] = 16;
  642.     IMP_chmap [188] = 17;
  643.     IMP_chmap [189] = 18;
  644.     IMP_chmap [190] = 19;
  645.     IMP_chmap [191] = 15;
  646.     IMP_chmap [192] = 65;
  647.     IMP_chmap [193] = 65;
  648.     IMP_chmap [194] = 65;
  649.     IMP_chmap [195] = 65;
  650.     IMP_chmap [196] = 65;
  651.     IMP_chmap [197] = 3;
  652.     IMP_chmap [198] = 1;
  653.     IMP_chmap [199] = 67;
  654.     IMP_chmap [200] = 69;
  655.     IMP_chmap [201] = 69;
  656.     IMP_chmap [202] = 69;
  657.     IMP_chmap [203] = 69;
  658.     IMP_chmap [204] = 73;
  659.     IMP_chmap [205] = 73;
  660.     IMP_chmap [206] = 73;
  661.     IMP_chmap [207] = 73;
  662.     IMP_chmap [208] = 68;
  663.     IMP_chmap [209] = 78;
  664.     IMP_chmap [210] = 79;
  665.     IMP_chmap [211] = 79;
  666.     IMP_chmap [212] = 79;
  667.     IMP_chmap [213] = 79;
  668.     IMP_chmap [214] = 79;
  669.     IMP_chmap [215] = 13;
  670.     IMP_chmap [216] = 2;
  671.     IMP_chmap [217] = 85;
  672.     IMP_chmap [218] = 85;
  673.     IMP_chmap [219] = 85;
  674.     IMP_chmap [220] = 85;
  675.     IMP_chmap [221] = 89;
  676.     IMP_chmap [222] = 32;
  677.     IMP_chmap [223] = 22;
  678.     IMP_chmap [224] = 97;
  679.     IMP_chmap [225] = 97;
  680.     IMP_chmap [226] = 97;
  681.     IMP_chmap [227] = 97;
  682.     IMP_chmap [228] = 97;
  683.     IMP_chmap [229] = 6;
  684.     IMP_chmap [230] = 4;
  685.     IMP_chmap [231] = 99;
  686.     IMP_chmap [232] = 101;
  687.     IMP_chmap [233] = 101;
  688.     IMP_chmap [234] = 101;
  689.     IMP_chmap [235] = 101;
  690.     IMP_chmap [236] = 105;
  691.     IMP_chmap [237] = 105;
  692.     IMP_chmap [238] = 105;
  693.     IMP_chmap [239] = 105;
  694.     IMP_chmap [240] = 100;
  695.     IMP_chmap [241] = 110;
  696.     IMP_chmap [242] = 111;
  697.     IMP_chmap [243] = 111;
  698.     IMP_chmap [244] = 111;
  699.     IMP_chmap [245] = 111;
  700.     IMP_chmap [246] = 111;
  701.     IMP_chmap [247] = 10;
  702.     IMP_chmap [248] = 5;
  703.     IMP_chmap [249] = 117;
  704.     IMP_chmap [250] = 117;
  705.     IMP_chmap [251] = 117;
  706.     IMP_chmap [252] = 117;
  707.     IMP_chmap [253] = 121;
  708.     IMP_chmap [254] = 32;
  709.     IMP_chmap [255] = 121;
  710. }
  711.  
  712. IMAGEN_createmap(name,map) 
  713. unsigned short *map; 
  714. int name; 
  715.     register int i,j; 
  716.     unsigned char s[4], *p; 
  717.  
  718.     p = s; 
  719.     *p++ = imP_CREATE_MAP; 
  720.     *p++ = name; 
  721.     j = 0; 
  722.     for (i=0;i<127;i++) { 
  723.         if ( map[i] ) j++; 
  724.     } 
  725.     *p = j; 
  726.     for (i=0;i<3;i++) putc(s[i],outfile); 
  727.  
  728.     s[3] = 1;
  729.     for (j=0;j<127;j++) { 
  730.         if ( map[j] ) { 
  731.             p = s; 
  732.             *p++ = j; 
  733.             *p++ = map[j] >> 8; 
  734.             *p   = map[j] & 255;
  735.             for (i=0;i<4;i++) putc(s[i],outfile); 
  736.         } 
  737.     } 
  738.  
  739.